/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean;

import entity.BranchEntity;
import entity.TouristAccountEntity;
import entity.FnBBranchEntity;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import org.primefaces.event.SelectEvent;
import session.stateful.BranchSessionBeanStateful;
import session.stateful.VisitorSessionBean;

/**
 *
 * @author Dell
 */
@ManagedBean
@SessionScoped
public class VisitorManagerBean {

    @EJB
    VisitorSessionBean visitorSessionBean;
    @EJB
    BranchSessionBeanStateful branchSessionBean;
    private long visitorId;
    private TouristAccountEntity customer;
    private List<FnBBranchEntity> fnBBranchList;
    private List<BranchEntity> branchList;
    private BranchEntity selectedBranch;

    public VisitorManagerBean() {
    }

    public void retrieveVisitorInfoById(ActionEvent event) {
        customer = visitorSessionBean.retrieveVisitorInfoById(getVisitorId());
        System.out.println(customer == null);
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("tourist", customer);
    }

    public void initBranchList(PhaseEvent event) {
        branchList = branchSessionBean.getAllBranch();
        setFnBBranchList(new ArrayList<FnBBranchEntity>());
        for (BranchEntity obj : branchList) {
            if (obj instanceof FnBBranchEntity) {
                getFnBBranchList().add((FnBBranchEntity) obj);
            }
        }
    }

    public String onRowSelectNavigateFnBBranch(SelectEvent event) {
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("tourist", customer);
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("branchId", selectedBranch.getId());
        System.out.println("Pass value " + selectedBranch.getId());
        return "tourist/VisitorIndicateDateAndQuantity?faces-redirect=true";
    }

    public long getVisitorId() {
        return visitorId;
    }

    public void setVisitorId(long visitorId) {
        this.visitorId = visitorId;
    }

    public TouristAccountEntity getTourist() {
        return customer;
    }

    public void setTourist(TouristAccountEntity customer) {
        this.customer = customer;
    }

    public List<FnBBranchEntity> getFnBBranchList() {
        return fnBBranchList;
    }

    public void setFnBBranchList(List<FnBBranchEntity> fnBBranchList) {
        this.fnBBranchList = fnBBranchList;
    }

    public BranchEntity getSelectedBranch() {
        return selectedBranch;
    }

    public void setSelectedBranch(BranchEntity selectedBranch) {
        this.selectedBranch = selectedBranch;
    }
}
